package v2;
import java.awt.Dimension;


public class ParticleRectangle extends ParticleShape {

	private Dimension topLeft;
	private Dimension bottomRight;
	private double density;

	public ParticleRectangle(Dimension topLeft, Dimension bottomRight, double density) {
		this.topLeft = topLeft;
		this.bottomRight = bottomRight;
		this.density = density;
		generateParticles();
	}

	public ParticleRectangle(double x, double y, double width, double height,
			double density) {
		this.topLeft = new Dimension((int)x,(int)y);
		this.bottomRight = new Dimension((int)(x+width),(int)(y+height));
		this.density = density;
		generateParticles();
	}

	private void generateParticles() {
		double x1 = bottomRight.getWidth();
		double x2 = topLeft.getWidth();
		double y1 = bottomRight.getHeight();
		double y2 = topLeft.getHeight();
		
		double perimeter = 2.*(x1-x2+y1-y2);
		double lineDensity = perimeter/density;

		for(double h = y2; h <= y1;h+=lineDensity){
			add(new StaticParticle(x1,h));
			add(new StaticParticle(x2,h));
		}
		for(double w = x2; w <= x1;w+=lineDensity){
			add(new StaticParticle(w,y1));
			add(new StaticParticle(w,y2));
		}
	}
}
